package ${jpad.packageName}.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wing.common.util.PageBean;
import ${jpad.packageName}.domain.${jpad.domainName};
import ${jpad.packageName}.service.${jpad.domainName}Manager;

/**
 * 
 * 
 * @author please  write your big name
 * 
 */
 
@Controller
@RequestMapping(value = "/${jpad.moduleName}/${jpad.domainName?lower_case}")
public class ${jpad.domainName}Controller {

	@Autowired
	private ${jpad.domainName}Manager ${jpad.domainName?lower_case}Manager;
	
	/**
	 * 获得列表数据
	 *  
	 */
	@RequestMapping(method = RequestMethod.GET)
	public String list() {
		return "/${jpad.moduleName}/${jpad.domainName?lower_case}/${jpad.domainName?lower_case}Index";
	}
	
	@RequestMapping(value = "get/{url}", method = RequestMethod.GET)
	public String delete(@PathVariable String url) {
		return "/${jpad.moduleName}/${jpad.domainName?lower_case}/"+url;
	}
		
	@RequestMapping(value = "list", method = RequestMethod.POST)
	public @ResponseBody PageBean list(int currentPage, String pageSize) {
		int _iPageSize = 0;
		if (pageSize == null) {
			_iPageSize = PageBean.DEFAULT_PAGESIZE;
		} else {
			_iPageSize= Integer.parseInt(pageSize);
		}
		return  ${jpad.domainName?lower_case}Manager.findPageList(currentPage, _iPageSize);
	}
	
	/**
	 * 打开编辑页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "toForm/{id}", method = RequestMethod.GET)
	public String toEditPage(@PathVariable String id, Model model) {
		${jpad.domainName} ${jpad.domainName?lower_case} = null;
		if(!id.equals("0")){
			${jpad.domainName?lower_case} = ${jpad.domainName?lower_case}Manager.findById(id);
		}else{
			${jpad.domainName?lower_case} = new ${jpad.domainName}();
		}
		model.addAttribute("${jpad.domainName?lower_case}", ${jpad.domainName?lower_case});
		return "/${jpad.moduleName}/${jpad.domainName?lower_case}/${jpad.domainName?lower_case}Form";
	}
	
	
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public  @ResponseBody  String save(${jpad.domainName} ${jpad.domainName?lower_case}) {
		${jpad.domainName?lower_case}Manager.save${jpad.domainName}(${jpad.domainName?lower_case});
		return "success";
	}
	
	@RequestMapping(value = "del${jpad.domainName?lower_case}s", method = RequestMethod.POST)
	public @ResponseBody String del${jpad.domainName?lower_case}s(String[] chk) throws IOException {
		${jpad.domainName?lower_case}Manager.delete${jpad.domainName}s(chk);
		return ""+chk.length;
	}
}
